project(
	'WayQt',
	'c',
	'cpp',
	version: '0.2.0',
	license: 'MIT',
	meson_version: '>=0.59.0',
	default_options: [
		'cpp_std=c++17',
		'c_std=c11',
		'warning_level=2',
		'werror=false',
	],
)

add_project_arguments( '-DPROJECT_VERSION="v@0@"'.format( meson.project_version() ), language : 'cpp' )
add_project_link_arguments( ['-rdynamic','-fPIC'], language:'cpp' )


if get_option('use_qt_version') == 'qt5'
	Qt     = import( 'qt5' )
	QtDeps = dependency(
		'qt5',
		modules: [ 'Core', 'Gui', 'WaylandClient', 'XkbCommonSupport' ],
		private_headers: [ 'Gui', 'WaylandClient', 'XkbCommonSupport' ],
	)

	# Nothing
	QtGlobal = []

	libname = 'wayqt'
	subdirname = 'DFL/DF5'

elif get_option('use_qt_version') == 'qt6'
	Qt     = import( 'qt6' )
	QtDeps = dependency(
		'qt6',
		modules: [ 'Core', 'Gui', 'WaylandClient' ],
		private_headers: [ 'Gui', 'WaylandClient', 'WaylandGlobalPrivate' ],
	)

	qmake = find_program( [ 'qmake-qt6', 'qmake6' ], required: true )
	ret = run_command( qmake, '-query', 'QT_INSTALL_HEADERS', check: true )
	QtHeaderPath = ret.stdout().strip()

	QtGlobal = '@0@/QtWaylandGlobal/@1@'.format( QtHeaderPath, QtDeps.version() )

	libname = 'wayqt-qt6'
	subdirname = 'DFL/DF6'

endif

wayland_client = dependency( 'wayland-client' )
rt = meson.get_compiler( 'cpp' ).find_library( 'rt' )

subdir( 'protocols' )

WQtHeaders = [
	'includes/wayqt/DataControl.hpp',
	'includes/wayqt/DesQShell.hpp',
	'includes/wayqt/GammaControl.hpp',
	'includes/wayqt/Idle.hpp',
	'includes/wayqt/InputInhibition.hpp',
	'includes/wayqt/LayerShell.hpp',
	'includes/wayqt/Output.hpp',
	'includes/wayqt/OutputManager.hpp',
	'includes/wayqt/OutputPowerManager.hpp',
	'includes/wayqt/Registry.hpp',
	'includes/wayqt/ScreenCopy.hpp',
	'includes/wayqt/SessionLock.hpp',
	'includes/wayqt/ShortcutsInhibitor.hpp',
	'includes/wayqt/ToplevelManager.hpp',
	'includes/wayqt/WayfireShell.hpp',
	'includes/wayqt/WayQtUtils.hpp',
	'includes/wayqt/WindowManager.hpp',
	'includes/wayqt/WlrIdle.hpp',
	'includes/wayqt/XdgActivation.hpp',
	'includes/wayqt/XdgPopup.hpp',
	'includes/wayqt/XdgPositioner.hpp',
	'includes/wayqt/XdgShell.hpp',
	'includes/wayqt/XdgTopLevel.hpp'
]

WQtImplHeaders = [
    'src/DataControlImpl.hpp',
    'src/LayerShellImpl.hpp',
]

WQtSources = [
	'src/DataControl.cpp',
	'src/DataControlImpl.cpp',
	'src/DesQShell.cpp',
	'src/GammaControl.cpp',
	'src/Idle.cpp',
	'src/InputInhibition.cpp',
	'src/LayerShell.cpp',
	'src/LayerShellImpl.cpp',
	'src/Output.cpp',
	'src/OutputManager.cpp',
	'src/OutputPowerManager.cpp',
	'src/Registry.cpp',
	'src/ScreenCopy.cpp',
	'src/SessionLock.cpp',
	'src/ShortcutsInhibitor.cpp',
	'src/ToplevelManager.cpp',
	'src/WayfireShell.cpp',
	'src/WayQtUtils.cpp',
	'src/WindowManager.cpp',
	'src/WlrIdle.cpp',
	'src/XdgActivation.cpp',
	'src/XdgPopup.cpp',
	'src/XdgPositioner.cpp',
	'src/XdgShell.cpp',
	'src/XdgTopLevel.cpp'
]

Preproc = Qt.preprocess(
 	moc_headers : [WQtHeaders, WQtImplHeaders],
	dependencies: QtDeps
)

WQt_deps = [ protos, QtDeps, wayland_client ]
includes = [ 'includes/', QtGlobal ]

wayqt = shared_library(
    libname, [ WQtSources, Preproc ],
	version: meson.project_version(),
	include_directories: [ includes ],
    dependencies: [WQt_deps, rt],
    install: true,
    install_dir: join_paths( get_option( 'libdir' ) )
)

install_subdir(
	'includes/wayqt',
	install_dir: join_paths( get_option( 'includedir' ), subdirname ),
)

summary = [
	'',
	'------------',
	'WayQt @0@'.format( meson.project_version() ),
	'------------',
	''
]
message( '\n'.join( summary ) )

## PkgConfig Section
pkgconfig = import( 'pkgconfig' )
pkgconfig.generate(
	wayqt,
	name: libname,
	subdirs: subdirname,
	version: meson.project_version(),
	filebase: libname,
	description: 'Qt Wrapper for Wayland, Wlroots and related protocols',
)
